package com.base.cn.platform.os.controller.web.classes.index;

import com.base.cn.platform.os.common.WebBaseController;
import com.base.cn.platform.os.common.utils.count.PageFrom;
import com.base.cn.platform.os.common.utils.count.PageKeyUtils;
import com.base.cn.platform.os.common.utils.result.ResultUtil;
import com.base.cn.platform.os.service.course.classes.ClassesService;
import com.base.cn.platform.os.service.manage.count.PageViewCountService;
import com.base.cn.platform.os.service.manage.op.advert.OpAdvertService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 班级首页
 *
 * @author SK
 * @since 2018-05-28
 */
@Controller
@RequestMapping("/web/classes")
public class WebClassesIndexController extends WebBaseController {

    @Autowired
    private ClassesService classesService;
    @Autowired
    private OpAdvertService opAdvertService;
    @Autowired
    private PageViewCountService pageViewCountService;

    /**
     * 班级首页页面
     *
     * @return 班级首页页面
     */
    @RequestMapping("/index")
    public String index() {
        pageViewCountService.addPageCount(PageKeyUtils.CLASS_INDEX, PageFrom.PAGE_FROM_PC);
        return resultPage("/classes/index/classes-index");
    }

    /**
     * 获取广告图片
     * @return
     */
    @RequestMapping("/getAdvertList")
    @ResponseBody
    public Map<String,Object> getAdvertList(){
        Map<String, Object> params = new HashMap<>();
        params.put("placeKey", "CLASSINDEX");
        params.put("status",1);
        List<Map<String, Object>> advertList = opAdvertService.queryAdvertList(params, false, false, false);
        return ResultUtil.SUCCESS(advertList);
    }

    /**
     * 班级列表页面
     *
     * @param params      班级查询条件
     * @param currentPage 第N页
     * @return 班级列表页面
     */
    @RequestMapping("/ajaxClassesList")
    public String ajaxClassesList(Model model,
                                  @RequestBody Map<String, Object> params,
                                  @RequestParam(value = "currentPage", required = false, defaultValue = "1") Integer currentPage) {
        params.put("status",1);
        Map<String, Object> dataMap = classesService.findClassesListPage(params, currentPage, 9, false, false, false, false);
        model.addAttribute("dataMap", dataMap);
        model.addAttribute("classesType",params.get("classesType"));
        return resultPage("/classes/index/ajax-classes-list");
    }
}
